<template>
  <div>
    <el-table fit border highlight-current-row :data="list" height="600" @current-change="handleChange">
      <el-table-column type="index" width="80" align="center" label="序号"></el-table-column>
      <el-table-column label="ID" align="center" prop="msid"></el-table-column>
      <el-table-column label="内容" align="center" prop="content"></el-table-column>
      <el-table-column label="描述" align="center" prop="text"></el-table-column>
      <el-table-column label="状态" align="center" prop="status"></el-table-column>
      <el-table-column label="审稿人" align="center" prop="reader"></el-table-column>
      <el-table-column label="类型" align="center" prop="title"></el-table-column>
      <el-table-column label="期刊" align="center" prop="journal"></el-table-column>
      <el-table-column label="建议" align="center">
        <template slot-scope="scope">
          <div>
            <el-tag>{{scope.row.suggestion}}</el-tag>
          </div>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center">
        <template slot-scope="scope">
          <div>
            <el-button type="success" icon="el-icon-edit" @click="handleReply(scope.row)">回复修改</el-button>
          </div>
        </template>
      </el-table-column>
    </el-table>
    <el-dialog title="回复修改" :visible.sync="updateDialog">
      <el-form :model="formData">
        <el-form-item label="email:">
          <el-input v-model="formData.email" readonly></el-input>
        </el-form-item>
        <!-- <el-form-item label="Id">
          <el-input v-model="formData.msId" readonly></el-input>
        </el-form-item> -->
        <el-form-item label="描述">
          <el-input v-model="formData.text"></el-input>
        </el-form-item>
        <el-form-item label="文件">
          <el-upload
            class="upload-demo"
            action="/api/file/upload"
            :on-success="handleSuccess"
          >
            <el-button type="primary">点击上传</el-button>
            <div slot="tip" class="el-upload__tip">请重新上传pdf文件</div>
          </el-upload>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="updateDialog = false">取消</el-button>
        <el-button type="success" @click="reply">确定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import axios from 'axios'
import { getManuscript, replyModification } from '@/api/manuscript'
const email = localStorage.getItem('email')
export default {
  name: 'ManuscriptList',
  data () {
    return {
      list: [],
      updateDialog: false,
      formData: {
        email: '',
        text: '',
        msId: '',
        file: ''
      }
    }
  },
  created () {
    this.getManuscript()
  },
  mounted () {
    this.getManuscript()
  },
  methods: {
    handleSuccess (response, file, fileList) {
      this.formData.file = response.data
    },
    handleChange (val) {
      if (val !== null) {
        // console.log(val)
      }
    },
    handleReply (row) {
      // console.log(row)
      axios.get(`api/manuscript/getManuscript/${row.msid}`).then(res => {
        console.log(res)
        this.updateDialog = true
        this.formData.email = email
        this.formData.text = res.data.data.text
        this.formData.msId = res.data.data.msid
        // this.formData.file = res.data.data.content
      }).catch(() => {})
      // this.formData = row
    },
    reply () {
      this.$confirm('确定修改？', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消'
      }).then(() => {
        replyModification(this.formData).then(res => {
          console.log(res)
          this.$message.success('修改成功')
          this.updateDialog = false
        }).catch(() => {})
      }).catch(() => {
        this.$message.info('已取消修改')
      })
    },
    getManuscript () {
      getManuscript({
        email: email
      }).then(res => {
        console.log(res)
        this.list = res.data.data
      }).catch(() => {})
    }
  }
}
</script>

<style scoped>

</style>
